package tr.edu.metu.is.mega.common.dto;

/**
 * Enumeration for user roles.
 */
public enum UserRole {

    ADMIN("A", "Administrator"),

    INSTRUCTOR("I", "Instructor"),

    ASSISTANT("T", "Assistant"),

    STUDENT("S", "Student");

    private String code;

    private String description;

    /**
     * Default constructor.
     * 
     * @param code code
     * @param description description
     */
    private UserRole(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * Returns the code.
     * 
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * Returns the description.
     * 
     * @return description
     */
    public String getDescription() {
        return description;
    }

    /**
     * Finds a user role by its code.
     * 
     * @param code code
     * @return user role
     */
    public static UserRole findByCode(String code) {
        for (UserRole role : UserRole.values()) {
            if (role.code.equals(code)) {
                return role;
            }
        }
        return null;
    }

}
